﻿using ASmile.Com;
using ASmile.Com.Menu;
using ASmile.DBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASmile.Win.DaBLL
{
    class MenuBLL : BLLBase, IMenuBLL
    {
        protected override string ControllerName => "SysManage/Menu";

        public ApiResultList<Sys_Menu> GetAllMenus()
        {
            var r = GetResultList<Sys_Menu>(null);
            return r;
        }

        #region 树形结构的操作

        /// <summary>
        /// 菜单分类列表（非菜单的树形结构）
        /// </summary>
        public ApiResultList<Sys_Menu> GetTreeData()
        {
            var r = GetResultList<Sys_Menu>();
            return r;
        }

        /// <summary>
        /// 新增树
        /// </summary>
        public ApiResult<string> AddTree(Sys_Menu m)
        {
            return GetResult<string>(m);
        }
        /// <summary>
        /// 编辑树
        /// </summary>
        public ApiResult<string> EditTree(Sys_Menu m)
        {
            return GetResult<string>(m);
        }
        /// <summary>
        /// 删除树
        /// </summary>
        public ApiResult DelTree(Sys_Menu m)
        {
            return GetResult<string>(m);
        }

        #endregion

        public ApiResult<string> AddMenu(Sys_Menu m)
        {
            return GetResult<string>(m);
        }

        public ApiResult<string> EditMenu(Sys_Menu m)
        {
            return GetResult<string>(m);
        }

        public ApiResult DelMenu(Sys_Menu m)
        {
            return GetResult<string>(m);
        }

        /// <summary>
        /// 根据父级Id获取所有子菜单
        /// </summary>
        public ApiResultList<Sys_Menu> GetMenus(ArgSearchMenu arg)//string pId, string searchValue = "")
        {
            return GetResultList<Sys_Menu>(arg);
        }

        /// <summary>
        /// 交换排序
        /// </summary>
        public ApiResult SwapOrderNo(Sys_Menu srcModel, Sys_Menu tarModel)
        {
            ArgSwapOrderNo arg = new ArgSwapOrderNo
            {
                SrcId = srcModel.Id,
                SrcOrderNo = srcModel.OrderNo,
                TarId = tarModel.Id,
                TarOrderNo = tarModel.OrderNo
            };
            var ret = GetResult(arg);
            tarModel.OrderNo += srcModel.OrderNo;
            srcModel.OrderNo = tarModel.OrderNo - srcModel.OrderNo;
            tarModel.OrderNo = tarModel.OrderNo - srcModel.OrderNo;
            return ret;
        }

        public ApiResult SwapOrderNo(ArgSwapOrderNo arg)
        {
            return GetResult(arg);
        }



        public ApiResult SetOrderNo(ArgSetSortNo arg)
        {
            return GetResult(arg);
        }

        public ApiResult SetParent(ArgSetParent arg)
        {
            return GetResult(arg);
        }
    }
}
